Skip to content

Comments

Cli add app CRUS and whoami and improve CLI speed by lazy loading#958

Merged
zeiler merged 3 commits intomasterfrom
cli-adds
Feb 23, 2026
Merged

Cli add app CRUS and whoami and improve CLI speed by lazy loading#958
zeiler merged 3 commits intomasterfrom
cli-adds

Conversation

@zeiler
Copy link
Member

@zeiler zeiler commented Feb 21, 2026

This pull request introduces several improvements and new features to the CLI, focusing on lazy command loading, enhanced user context handling, new app management commands, and expanded test coverage for configuration logic. The most important changes are grouped below by theme.

CLI Command Loading and Structure

  • Introduced the LazyAliasedGroup class in clarifai/utils/cli.py, enabling lazy loading of CLI command modules for improved startup performance and command aliasing. All CLI groups now use this class instead of AliasedGroup. ([[1]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-e3cafb4277139ff82e1f80b80b5dcc839f4420b365d79d97c44206e151e6eeb1R329-R371), [[2]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-6b11868a510d65b7b8d2550d7a614cfad49fc8e5d709a9ef529343281c74edffL9-R19), [[3]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-6b11868a510d65b7b8d2550d7a614cfad49fc8e5d709a9ef529343281c74edffL61-R65))
  • Removed eager loading of command modules in clarifai/cli/base.py, now handled lazily by LazyAliasedGroup. ([clarifai/cli/base.pyL542-R594](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-6b11868a510d65b7b8d2550d7a614cfad49fc8e5d709a9ef529343281c74edffL542-R594))

App Management CLI

  • Added a new app command group to clarifai/cli/app.py for managing apps, including subcommands for creating, listing, and deleting apps. ([clarifai/cli/app.pyR1-R85](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-cf5647745ef431e4ab42c5bc51105695bc858a6cec995cbb2fec5adcfd1005dfR1-R85))

User Context and Authentication

  • Added a whoami command to clarifai/cli/base.py to display both the context user ID and the authenticated user ID, with warning if they differ. ([clarifai/cli/base.pyR127-R174](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-6b11868a510d65b7b8d2550d7a614cfad49fc8e5d709a9ef529343281c74edffR127-R174))

Artifact and Pipeline Template Command Refactoring

  • Moved imports for artifact and template management modules inside functions for improved lazy loading and startup performance. ([[1]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-d4cd19419e77075aa0829215b5c2bb2833fba3fb9ff58af1936bfca062ec4bc4L8-L13), [[2]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-d4cd19419e77075aa0829215b5c2bb2833fba3fb9ff58af1936bfca062ec4bc4R139-R140), [[3]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-d4cd19419e77075aa0829215b5c2bb2833fba3fb9ff58af1936bfca062ec4bc4R179-R182), [[4]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-d4cd19419e77075aa0829215b5c2bb2833fba3fb9ff58af1936bfca062ec4bc4R235-R240), [[5]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-d4cd19419e77075aa0829215b5c2bb2833fba3fb9ff58af1936bfca062ec4bc4R339-R343), [[6]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-d4cd19419e77075aa0829215b5c2bb2833fba3fb9ff58af1936bfca062ec4bc4R416-R418), [[7]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-c0f2809b0d9330cda23fba6162e0480c54a12740673a16086a03bfffe19371dfL10), [[8]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-c0f2809b0d9330cda23fba6162e0480c54a12740673a16086a03bfffe19371dfR39-R40), [[9]](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-c0f2809b0d9330cda23fba6162e0480c54a12740673a16086a03bfffe19371dfR106-R107))

Configuration Logic and Testing

  • Added comprehensive unit tests for the Config and Context classes in tests/client/test_config.py, covering environment variable overrides, direct access, fallbacks, and error handling. ([tests/client/test_config.pyR1-R232](https://github.com/Clarifai/clarifai-python/pull/958/files#diff-0774976c767ba9cc7410392dbf26231bcefdfd529d2dbe133c48af538d311c5bR1-R232))

@zeiler zeiler requested a review from luv-bansal February 21, 2026 17:53
@zeiler
Copy link
Member Author

zeiler commented Feb 21, 2026

@copilot can you fix the errors from https://github.com/Clarifai/clarifai-python/actions/runs/22261474947/job/64400373261?pr=958 i suspect that the new config test is clobbering the CLARIFAI_PAT and other env vars

Copy link
Contributor

Copilot AI commented Feb 21, 2026

@zeiler I've opened a new pull request, #959, to work on those changes. Once the pull request is ready, I'll request review from you.

…aths (#959)

* Initial plan

* Fix env var clobbering in test_config.py by using @patch.dict

Co-authored-by: zeiler <2138258+zeiler@users.noreply.github.com>

* Fix test patch paths broken by lazy loading refactor

Co-authored-by: zeiler <2138258+zeiler@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: zeiler <2138258+zeiler@users.noreply.github.com>
@github-actions
Copy link

Code Coverage

Package Line Rate Health
clarifai 45%
clarifai.cli 69%
clarifai.cli.templates 46%
clarifai.client 65%
clarifai.client.auth 67%
clarifai.constants 100%
clarifai.datasets 100%
clarifai.datasets.export 80%
clarifai.datasets.upload 75%
clarifai.datasets.upload.loaders 37%
clarifai.models 100%
clarifai.rag 0%
clarifai.runners 52%
clarifai.runners.models 64%
clarifai.runners.pipeline_steps 39%
clarifai.runners.pipelines 71%
clarifai.runners.utils 62%
clarifai.runners.utils.data_types 72%
clarifai.schema 100%
clarifai.urls 58%
clarifai.utils 61%
clarifai.utils.evaluation 16%
clarifai.workflows 95%
Summary 62% (10128 / 16415)

Minimum allowed line rate is 50%

@zeiler zeiler merged commit 399729d into master Feb 23, 2026
11 checks passed
@zeiler zeiler deleted the cli-adds branch February 23, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants